<template>
	<div class="app">
		<uni-list>
			<!--<uni-list-item title="修改密码"   @click="jumpMenuFn('修改密码')" ></uni-list-item>-->
			<uni-list-item title="修改手机号码" :text="userInfo.mobile_phone || userInfo.contact_phone" @click="jumpMenuFn('修改手机')"></uni-list-item>
			<!-- <uni-list-item title="首页模板"
						   @click="jumpMenuFn('首页模板')"
						   v-if="userInfo.role_id == 1"
						   :text="userInfo.user_template == 0 ? '专业版' : '基础版'">
			</uni-list-item>-->
			<uni-list-item title="切换角色" @click="jumpMenuFn('切换角色')" :text="userInfo.role_name"></uni-list-item>
			<uni-list-item title="分佣设置" @click="jumpMenuFn('分佣设置')"></uni-list-item>
		</uni-list>

		<button class="setting_btn" @click="loginout">退出登录</button>
	</div>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
import uniList from '@/components/uni-list/uni-list.vue'
import uniListItem from '@/components/uni-list-item/uni-list-item.vue'

import { getAccountList } from '@/api/common'

export default {
	name: 'settingindex',
	components: {
		uniList,
		uniListItem
	},
	data() {
		return {
			showStoreChange: false
		}
	},
	computed: {
		...mapGetters({ userInfo: 'getUser' })
	},
	onLoad(option) {
		let that = this
		that.option = option
		that.getAccountListFN()
	},
	methods: {
		getAccountListFN() {
			getAccountList().then(res => {
				if (res.data.childrenAccountList && res.data.childrenAccountList.length) {
					this.showStoreChange = true
				}
			})
		},
		jumpMenuFn(type) {
			let query = null
			switch (type) {
				case '修改手机':
					uni.navigateTo({
						url: '/pages/admin/setting/changePhone'
					})
					break
				case '首页模板':
					query = { owner_user_id: this.option.owner_user_id }
					uni.navigateTo({
						url: `/pages/admin/setting/decompanyTempEdit${this.commonJS.queryData(query)}`
					})
					break
				case '修改密码':
					query = { account: '张三' }
					uni.navigateTo({
						url: '/pages/admin/setting/changePassworld'
					})
					break
				case '切换角色':
					uni.navigateTo({
						url: '/pages/admin/setting/storeManagement'
					})
					break
				case '分佣设置':
					uni.navigateTo({
						url: '/pages/admin/setting/commission'
					})
					break
			}
		},

		// 退出登录
		loginout() {
			// uni.clearStorageSync()
			uni.removeStorageSync('token')
			uni.removeStorageSync('wxMobile')
			uni.removeStorageSync('user_id')
			uni.removeStorageSync('currentQuery')
			uni.removeStorageSync('basicUser')
			uni.removeStorageSync('userInfo')
			uni.removeStorageSync('userInfo')

			this.$store.dispatch('setBasicUser', null)
			this.$store.dispatch('setUser', null)
			uni.navigateTo({
				url: '/pages/page/login/index'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
	.app {
		height: 100%;
		background-color: $backColorMain;
		.setting_btn {
			width: 95%;
			height: 90px;
			font-size: 24px;
			color: #ff6900;
			border: none;
			line-height: 90px;
			background: white;
			border-radius:10px;
			margin-top: 60px;
			border: none;
			&::after {
				border: none;
			}
		}
	}
</style>
